//
//  SubscriberWalletSummaryModel.m
//
//  Created by mac  on 2018/11/28
//  Copyright (c) 2018 __MyCompanyName__. All rights reserved.
//

#import "SubscriberWalletSummaryModel.h"


NSString *const kSubscriberWalletSummaryModelUserID = @"UserID";
NSString *const kSubscriberWalletSummaryModelTodayCoinAdded = @"TodayCoinAdded";
NSString *const kSubscriberWalletSummaryModelAmount = @"Amount";
NSString *const kSubscriberWalletSummaryModelCoinAccount = @"CoinAccount";
NSString *const kSubscriberWalletSummaryModelAddress = @"Address";
NSString *const kSubscriberWalletSummaryModelYesterdayAmountAdded = @"YesterdayAmountAdded";
NSString *const kSubscriberWalletSummaryModelYeasterdayCoinAdded = @"YeasterdayCoinAdded";
NSString *const kSubscriberWalletSummaryModelTodayAmountAdded = @"TodayAmountAdded";


@interface SubscriberWalletSummaryModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation SubscriberWalletSummaryModel

@synthesize userID = _userID;
@synthesize todayCoinAdded = _todayCoinAdded;
@synthesize amount = _amount;
@synthesize coinAccount = _coinAccount;
@synthesize address = _address;
@synthesize yesterdayAmountAdded = _yesterdayAmountAdded;
@synthesize yeasterdayCoinAdded = _yeasterdayCoinAdded;
@synthesize todayAmountAdded = _todayAmountAdded;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.userID = [[self objectOrNilForKey:kSubscriberWalletSummaryModelUserID fromDictionary:dict] intValue];
            self.todayCoinAdded = [[self objectOrNilForKey:kSubscriberWalletSummaryModelTodayCoinAdded fromDictionary:dict] doubleValue];
            self.amount = [[self objectOrNilForKey:kSubscriberWalletSummaryModelAmount fromDictionary:dict] doubleValue];
            self.coinAccount = [[self objectOrNilForKey:kSubscriberWalletSummaryModelCoinAccount fromDictionary:dict] doubleValue];
            self.address = [self objectOrNilForKey:kSubscriberWalletSummaryModelAddress fromDictionary:dict];
            self.yesterdayAmountAdded = [[self objectOrNilForKey:kSubscriberWalletSummaryModelYesterdayAmountAdded fromDictionary:dict] doubleValue];
            self.yeasterdayCoinAdded = [[self objectOrNilForKey:kSubscriberWalletSummaryModelYeasterdayCoinAdded fromDictionary:dict] doubleValue];
            self.todayAmountAdded = [[self objectOrNilForKey:kSubscriberWalletSummaryModelTodayAmountAdded fromDictionary:dict] doubleValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithInt:self.userID] forKey:kSubscriberWalletSummaryModelUserID];
    [mutableDict setValue:[NSNumber numberWithDouble:self.todayCoinAdded] forKey:kSubscriberWalletSummaryModelTodayCoinAdded];
    [mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kSubscriberWalletSummaryModelAmount];
    [mutableDict setValue:[NSNumber numberWithDouble:self.coinAccount] forKey:kSubscriberWalletSummaryModelCoinAccount];
    [mutableDict setValue:self.address forKey:kSubscriberWalletSummaryModelAddress];
    [mutableDict setValue:[NSNumber numberWithDouble:self.yesterdayAmountAdded] forKey:kSubscriberWalletSummaryModelYesterdayAmountAdded];
    [mutableDict setValue:[NSNumber numberWithDouble:self.yeasterdayCoinAdded] forKey:kSubscriberWalletSummaryModelYeasterdayCoinAdded];
    [mutableDict setValue:[NSNumber numberWithDouble:self.todayAmountAdded] forKey:kSubscriberWalletSummaryModelTodayAmountAdded];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.userID = [aDecoder decodeIntegerForKey:kSubscriberWalletSummaryModelUserID];
    self.todayCoinAdded = [aDecoder decodeDoubleForKey:kSubscriberWalletSummaryModelTodayCoinAdded];
    self.amount = [aDecoder decodeDoubleForKey:kSubscriberWalletSummaryModelAmount];
    self.coinAccount = [aDecoder decodeDoubleForKey:kSubscriberWalletSummaryModelCoinAccount];
    self.address = [aDecoder decodeObjectForKey:kSubscriberWalletSummaryModelAddress];
    self.yesterdayAmountAdded = [aDecoder decodeDoubleForKey:kSubscriberWalletSummaryModelYesterdayAmountAdded];
    self.yeasterdayCoinAdded = [aDecoder decodeDoubleForKey:kSubscriberWalletSummaryModelYeasterdayCoinAdded];
    self.todayAmountAdded = [aDecoder decodeDoubleForKey:kSubscriberWalletSummaryModelTodayAmountAdded];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeInteger:_userID forKey:kSubscriberWalletSummaryModelUserID];
    [aCoder encodeDouble:_todayCoinAdded forKey:kSubscriberWalletSummaryModelTodayCoinAdded];
    [aCoder encodeDouble:_amount forKey:kSubscriberWalletSummaryModelAmount];
    [aCoder encodeDouble:_coinAccount forKey:kSubscriberWalletSummaryModelCoinAccount];
    [aCoder encodeObject:_address forKey:kSubscriberWalletSummaryModelAddress];
    [aCoder encodeDouble:_yesterdayAmountAdded forKey:kSubscriberWalletSummaryModelYesterdayAmountAdded];
    [aCoder encodeDouble:_yeasterdayCoinAdded forKey:kSubscriberWalletSummaryModelYeasterdayCoinAdded];
    [aCoder encodeDouble:_todayAmountAdded forKey:kSubscriberWalletSummaryModelTodayAmountAdded];
}

- (id)copyWithZone:(NSZone *)zone
{
    SubscriberWalletSummaryModel *copy = [[SubscriberWalletSummaryModel alloc] init];
    
    if (copy) {

        copy.userID = self.userID;
        copy.todayCoinAdded = self.todayCoinAdded;
        copy.amount = self.amount;
        copy.coinAccount = self.coinAccount;
        copy.address = [self.address copyWithZone:zone];
        copy.yesterdayAmountAdded = self.yesterdayAmountAdded;
        copy.yeasterdayCoinAdded = self.yeasterdayCoinAdded;
        copy.todayAmountAdded = self.todayAmountAdded;
    }
    
    return copy;
}


@end
